package com.study.加密;

import java.io.*;

/**
 * @author HBZ
 * @description
 * @date 2021/6/21 18:49
 */
public class IOSercet {
    private static final  String  path="E:\\my\\照片\\";
    public static void main(String[] args) throws IOException {

        String file="调小版.png";
//        decrypt("C:\\Users\\Dell\\Desktop\\原视频.avi");
//        secret(path+file);
        decrypt(path+"_new.png");
    }

    //加密
    public static void secret(String str) throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(str));
        String [] s=str.split("\\.");
        BufferedOutputStream bos = new BufferedOutputStream(new
                FileOutputStream(path+"_new."+s[1]));
        int n;
        long a=System.currentTimeMillis();
        while((n=bis.read())!=-1){
            bos.write(n+22);
        }
        long b=System.currentTimeMillis();
        bis.close();
        bos.close();
        System.out.println("加密拷贝成功！");
        System.out.println("加密用时："+(b-a)+"ms");
    }




    //解密
    public static void decrypt(String str) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(str));
        String [] s=str.split("\\.");
        BufferedOutputStream bos = new BufferedOutputStream(new
                FileOutputStream(path+"2."+s[1]));
        int n;
        long a=System.currentTimeMillis();
        while((n=bis.read())!=-1){
            bos.write(n-22);
        }
        long b=System.currentTimeMillis();
        bis.close();
        bos.close();
        System.out.println("解密拷贝成功！");
        System.out.println("解密用时："+(b-a)+"ms");
    }

}
